package idv.ccApp.cwFileExplore;

import android.content.Context;
import android.util.Log;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

/**
 * Created with IntelliJ IDEA.
 * User: ajax
 * Date: 2013/6/29
 * Time: 下午 9:32
 * To change this template use File | Settings | File Templates.
 */
public class MySimpleGestureListener extends GestureDetector.SimpleOnGestureListener {
  private String TAG = "PDFSGL";
  private final int SWIPE_MIN_DISTANCE = 120;
  private final int SWIPE_THRESHOLD_VELOCITY = 200;

  private ViewFlipper mViewFlipper;
  private Context ctx;
  public MySimpleGestureListener(Context ct, ViewFlipper fli){
    this.ctx = ct;
    this.mViewFlipper = fli;
  }

  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    Log.e(TAG, "onFling()");
    if (e1.getX() - e2.getX() > 120) {
      this.mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(this.ctx, R.anim.push_left_in));
      this.mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this.ctx, R.anim.push_left_out));
      this.mViewFlipper.showNext();
      Log.d(TAG, e1.getX() + "   " + e2.getX());
      return true;
    } else if (e1.getX() - e2.getX() < -120) {
      this.mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(this.ctx, R.anim.push_right_in));
      this.mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this.ctx, R.anim.push_right_out));
      this.mViewFlipper.showPrevious();
      return true;
    }
    return false;
  }

  /*
  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    return super.onFling(e1, e2, velocityX, velocityY);    //To change body of overridden methods use File | Settings | File Templates.
  }
  */
}
